﻿using Microsoft.Practices.Unity;
using Sasa.QualityTools.CodeAnalysis.Core.VisualStudio;

namespace Sasa.QualityTools.CodeAnalysis.FxCopIntegrator.Commands.Behaviors.Building
{
    public class BuildProjectBehavior : ICommandBehavior<CodeAnalysisCommandExecutionContext>
    {
        private IUnityContainer container;


        public BuildProjectBehavior(IUnityContainer container)
        {
            this.container = container;
        }


        public void Behave(CodeAnalysisCommandExecutionContext context)
        {
            var ide = container.Resolve<IIde>();
            var project = ide.Solution.CurrentProject;

            if (!project.Build())
            {
                context.Cancel("Stopped code analysis because build failed.", () => ide.ShowError());
                return;
            }
        }
    }
}
